package com.example.baseapp.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.baseapp.admin.entity.Role;
import com.example.baseapp.admin.mapper.RoleMapper;
import com.example.baseapp.admin.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户角色表(Role)表服务实现类
 *
 * @author zhanglei
 * @since 2022-04-28 14:24:39
 */
@Service("roleService")
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param roleId 主键
     * @return 实例对象
     */
    @Override
    public Role queryById(String roleId) {
        return this.roleMapper.selectOne(new LambdaQueryWrapper<Role>().eq(Role::getRoleId,roleId));
    }

    @Override
    public List<Role> queryById(String... roleIds) {
        return roleMapper.selectList(new LambdaQueryWrapper<Role>().in(roleIds.length > 0,Role::getRoleId,roleIds));
    }

    @Override
    public List<Role> queryById(List<String> roleIdList) {
        return  roleMapper.selectList(new LambdaQueryWrapper<Role>().in(Role::getRoleId,roleIdList));
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */

    public List<Role> queryAllByLimit(int offset, int limit) {
        return  new ArrayList<>();
    }

    /**
     * 新增数据
     *
     * @param role 实例对象
     * @return 实例对象
     */
    @Override
    public Role insert(Role role) {
        this.roleMapper.insert(role);
        return role;
    }

    /**
     * 修改数据
     *
     * @param role 实例对象
     * @return 实例对象
     */
    @Override
    public Role update(Role role) {
        this.roleMapper.updateById(role);
        return this.queryById(role.getRoleId());
    }

    @Override
    public boolean deleteById(String roleId) {
        return false;
    }


}